<template>
	<view class="item">
		<view @click="show=!show"
			style="margin: 5px 0;display: flex;align-items: center;justify-content: space-between;">
			<view style="display: flex;align-items: center;">
				<u-avatar :src="getIcon(item.disk_type)" size="35"></u-avatar>
				<view style="margin-left: 5px;">
					<u--text :text="item.disk_name" lines="1" size="16"></u--text>
					<p style="font-size: 12px;color: #909399;">{{item.shared_time}}</p>
				</view>
			</view>
			<view>
				<u-icon name="more-dot-fill" size="20"></u-icon>
			</view>
		</view>
		<view @click="show=!show" v-if="item.files.length>0" class="files">
			<view class="file-item" :key="index" v-for="(it,index) in item.files">
				<image :src="getSuffix(it.suffix)"></image>
				<u--text color="#434343" :text="it.name" lines="1" size="12"></u--text>
			</view>
		</view>
		<view @click="show=!show" style="display: flex;align-items: center;justify-content:flex-end;margin-top: 5px;">
			<p style="font-size: 13px;color: #606266;">{{item.disk_type}}</p>
			<!-- 	<view style="display: flex;align-items: center;">
				<u-icon v-if="effective!='ok'" color="#c8c9cc" name="close-circle-fill" size="20"></u-icon>
				<u-icon v-else name="checkmark-circle-fill" color="#19be6b" size="20"></u-icon>
				<p v-if="effective!='ok'" style="font-size: 12px;margin-left: 5px;color:#c8c9cc">无效</p>
				<p v-else style="font-size: 12px;margin-left: 5px;color:#19be6b">有效</p>
			</view> -->
		</view>
		<u-action-sheet @select="select" cancelText="取消" @close="show=false" :closeOnClickOverlay="true"
			:closeOnClickAction="true" :actions="list" :show="show"></u-action-sheet>
	</view>
</template>

<script>
	export default {
		props: ["item"],
		name: "panItem",
		data() {
			return {
				effective: "ok",
				list: [{
						name: '浏览器打开'
					}, {
						name: '复制链接'
					},
					{
						name: '举报资源',
					}
				],
				show: false
			}
		},
		methods: {
			select(e) {
				if (e.name == "复制链接") {
					this.copy(this.item.disk_link)
				} else if (e.name == "举报资源") {
					this.goPage('feedback', '?type=pan&id=' + this.item.doc_id)
				} else if (e.name == "浏览器打开") {
					this.openUrl(this.item.disk_link)
				}
			},
			getIcon(type) {
				if (type == "夸克网盘") {
					return "../../static/pan/kk.png"
				} else if (type == "百度网盘") {
					return "../../static/pan/bd.png"
				} else if (type == "阿里云盘") {
					return "../../static/pan/al.png"
				} else if (type == "迅雷网盘") {
					return "../../static/pan/xl.png"
				} else {
					return "../../static/pan/uc.png"
				}
			},
			getSuffix(suffix) {
				if (suffix == ".mp4" || suffix == ".avi" || suffix == ".mov" || suffix == ".wmv" || suffix == ".flv" ||
					suffix == ".mkv") {
					return "../../static/filetype/shipin-mov_mp4_avi.png"
				} else if (suffix == ".zip" || suffix == ".rar" || suffix == ".jar" || suffix == ".7z") {
					return "../../static/filetype/yasuowenjian-zip_rar_7z.png"
				} else if (suffix == ".apk") {
					return "../../static/filetype/apk.png"
				} else if (suffix == ".xlxs" || suffix == ".xls") {
					return "../../static/filetype/biaoge-xlxs_xls.png"
				} else if (suffix == ".exe") {
					return "../../static/filetype/exe.png"
				} else if (suffix == ".html" || suffix == ".htm") {
					return "../../static/filetype/h5.png"
				} else if (suffix == ".pdf") {
					return "../../static/filetype/pdf.png"
				} else if (suffix == ".docx" || suffix == ".doc") {
					return "../../static/filetype/wendang-docx_doc.png"
				} else if (suffix == ".ppt" || suffix == ".pptx") {
					return "../../static/filetype/yanshiwendang-ppt_pptx.png"
				} else if (suffix == ".jpg" || suffix == ".png") {
					return "../../static/filetype/tupian-jpg_png.png"
				} else if (suffix == ".mp3" || suffix == ".wav" || suffix == ".flac") {
					return "../../static/filetype/yinle-music.png"
				} else if (suffix == "" || /\d/.test(suffix)) {
					return "../../static/filetype/morenwenjianjia.png"
				} else if (suffix == ".txt") {
					return "../../static/filetype/wenbenwendang-txt.png"
				} else {
					return "../../static/filetype/qita.png"
				}
			},
			async getEffective() {
				const res = await uni.request({
					url: "https://hunhepan.com/v1/raw_disk/check/" + this.item.doc_id,
					method: "GET"
				})
				this.effective = res.data.data
				console.log(res.data.data);
			}
		},
		mounted() {
			// this.getEffective()
		}
	}
</script>

<style scoped lang="scss">
	.btns {
		display: flex;
		margin-top: 10px;
	}

	.item {
		margin: 10px;
		background-color: white;
		padding: 10px;
		border-radius: 10px;
	}

	.files {
		background-color: #f0f0f0;
		padding: 10px;
		border-radius: 5px;
		display: flex;
		flex-direction: column;
		gap: 5px;
	}

	.file-item {
		display: flex;
		align-items: center;

		image {
			width: 20px;
			height: 20px;
			border-radius: 2px;
			margin-right: 5px;
		}
	}
</style>